package com.huluobo.a2212mdmdemo.video

import com.huluobo.lib_base.BaseViewModel
import com.huluobo.lib_base.Res2
import com.huluobo.lib_base.StateType
import com.huluobo.lib_base.UIIntent
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.Flow
import javax.inject.Inject

/**
 *  Created by LC on 2025/6/6.
 */
@HiltViewModel
class VideoViewModel @Inject constructor(private val videoRepo: VideoRepo) : BaseViewModel<VideoIntent>() {
    override fun handleIntent(it: UIIntent) {
        when (it) {
            is VideoIntent.GetVideos -> {
                httpRequestVideo(videoRepo.getVideos(it.currentPage, it.pageSize) as Flow<Res2<Any>>)
            }

            is VideoIntent.LikeVideo -> {
                httpRequestVideo(videoRepo.likeVideo(it.videoId))
            }

            is VideoIntent.GetComments -> {
                httpRequestVideo(videoRepo.getComments(it.videoId) as Flow<Res2<Any>>, StateType.COMMENT)
            }

            is VideoIntent.SendComment -> {
                httpRequestVideo(videoRepo.sendComment(it.map) as Flow<Res2<Any>>, StateType.SEND)
            }
        }
    }
}